﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NAnt.Core;
using NAnt.Core.Attributes;
using System.IO;
using CodeMadeSimple.Common.Exceptions;

namespace EnvRide.NAnt
{
    /// <summary>
    /// Base class for all EnvRide NAnt tasks.
    /// </summary>
    public abstract class EnvRideBaseTask : Task
    {
        private String _filePath;

        /// <summary>
        /// Path to the xml file to parse.
        /// </summary>
        [StringValidator(AllowEmpty = false)]
        [TaskAttribute("filepath", Required = true)]
        public String FilePath
        {
            get { return _filePath; }
            set { _filePath = value; }
        }

        protected override void ExecuteTask()
        {
            Log(Level.Verbose, "Processing file: {0}...", FilePath);

            if (String.IsNullOrEmpty(FilePath))
                throw ExceptionsHelper.GetStringException("FilePath", FilePath);

            if (!File.Exists(FilePath))
                throw new FileNotFoundException(String.Format("The file \"{0}\" was not found!", FilePath));
        }
    }
}
